home *** CD-ROM | disk | FTP | other *** search
/ PC Open 96 / PC Open 96 CD3.bin / fscommand / index.swf / scripts / %3Cdefault package%3E / SUBTITLE.as < prev    next >
Encoding:
Text File  |  2004-01-08  |  6.3 KB  |  216 lines

  1. _global.synchroneCLASS = function()
  2. {
  3.    this.targetInitBytes = 0;
  4.    this.tftStyle = new TextFormat();
  5.    this.tftStyle.align = "center";
  6.    this.tftStyle.color = 16777215;
  7.    this.tftStyle.font = "eurostile";
  8.    this.tftStyle.size = 16;
  9.    this.backLimit = 50;
  10.    this.useShade = true;
  11.    this.useBox = false;
  12.    this.useSubtitle = false;
  13. };
  14. _global.synchroneCLASS.prototype.videoPreloader = function()
  15. {
  16.    var bounds;
  17.    this.target.gotoAndStop(1);
  18.    this.target._visible = false;
  19.    if(!this.useSubtitle)
  20.    {
  21.       trace(this.target.getBytesLoaded());
  22.       if(this.target.getBytesLoaded() != this.targetInitBytes)
  23.       {
  24.          clearInterval(this.videoPreloaderInterval);
  25.          this.target._visible = true;
  26.          this.onDataTarget[this.onDataMethod].apply(this.onDataTarget,this.onDataArguments);
  27.       }
  28.    }
  29.    else if(this.target.getBytesLoaded != this.targetInitBytes && this.target._framesloaded > _global.FPS && this.subParser.getBytesTotal() > 0 && this.subParser.getBytesLoaded() == this.subParser.getBytesTotal())
  30.    {
  31.       clearInterval(this.videoPreloaderInterval);
  32.       this.target._visible = true;
  33.       bounds = this.target.getBounds(this.target);
  34.       if(this.textX == null)
  35.       {
  36.          this.textX = (bounds.xMax - bounds.xMin) / 2 + bounds.xMin;
  37.       }
  38.       if(this.textY == null)
  39.       {
  40.          this.textY = bounds.yMax;
  41.       }
  42.       this.lastFrame = 1;
  43.       this.synchronizeInterval = setInterval(this,"synchronize",1000 / (_global.FPS + 1));
  44.       this.onDataTarget[this.onDataMethod]();
  45.    }
  46. };
  47. _global.synchroneCLASS.prototype.synchronize = function()
  48. {
  49.    var i;
  50.    var subText;
  51.    if(this.lastFrame == this.target._currentframe)
  52.    {
  53.       return undefined;
  54.    }
  55.    this.lastFrame = this.target._currentframe;
  56.    subText = null;
  57.    i = this.target._currentframe;
  58.    while(i > this.target._currentframe - this.backLimit)
  59.    {
  60.       if(this.subObj[i] != null)
  61.       {
  62.          if(this.target._currentframe < this.subObj[i].end)
  63.          {
  64.             subText = this.subObj[i].text;
  65.          }
  66.          break;
  67.       }
  68.       i--;
  69.    }
  70.    if(this.lastSubText != subText)
  71.    {
  72.       this.display(subText);
  73.    }
  74.    this.lastSubText = subText;
  75. };
  76. _global.synchroneCLASS.prototype.display = function(str)
  77. {
  78.    var lineArr;
  79.    var lines;
  80.    var extentHeight;
  81.    var lineExtent;
  82.    if(str == null)
  83.    {
  84.       if(this.tfSubBox instanceof TextField)
  85.       {
  86.          this.tfSubBox.removeTextField();
  87.       }
  88.       if(this.tfSubBoxShadow instanceof TextField)
  89.       {
  90.          this.tfSubBoxShadow.removeTextField();
  91.       }
  92.       if(this.mSubBox instanceof MovieClip)
  93.       {
  94.          this.mSubBox.removeMovieClip(this);
  95.       }
  96.       return undefined;
  97.    }
  98.    if(!(this.tfSubBox instanceof TextField))
  99.    {
  100.       this.target.createTextField("tfSubBox",3,this.textX,0,0,0);
  101.       this.tfSubBox = this.target.tfSubBox;
  102.       this.tfSubBox.selectable = false;
  103.       this.tfSubBox.autoSize = "center";
  104.       this.tfSubBox.html = true;
  105.       this.tfSubBox.embedFonts = true;
  106.    }
  107.    this.tfSubBox.htmlText = str.split("\n").join("<br>");
  108.    this.tfSubBox.setTextFormat(this.tftStyle);
  109.    this.tfSubBox._y = this.textY - this.tfSubBox._height;
  110.    if(this.useShade)
  111.    {
  112.       if(!(this.tfSubBoxShadow instanceof TextField))
  113.       {
  114.          this.target.createTextField("tfSubBoxShadow",2,this.textX + 1,0,0,0);
  115.          this.tfSubBoxShadow = this.target.tfSubBoxShadow;
  116.          this.tfSubBoxShadow.selectable = false;
  117.          this.tfSubBoxShadow.autoSize = "center";
  118.          this.tfSubBoxShadow.html = true;
  119.          this.tfSubBoxShadow.embedFonts = true;
  120.       }
  121.       this.tfSubBoxShadow.htmlText = str.split("\n").join("<br>");
  122.       this.tfSubBoxShadow.setTextFormat(this.tftStyle);
  123.       this.tfSubBoxShadow.textColor = 0;
  124.       this.tfSubBoxShadow._y = this.textY - this.tfSubBoxShadow._height + 1;
  125.    }
  126.    if(this.useBox)
  127.    {
  128.       if(!(this.mSubBox instanceof MovieClip))
  129.       {
  130.          this.mSubBox = this.target.createEmptyMovieClip("mSubBox",1);
  131.          this.mSubBox.beginFill(0,30);
  132.          this.mSubBox.lineTo(100,0);
  133.          this.mSubBox.lineTo(100,100);
  134.          this.mSubBox.lineTo(0,100);
  135.          this.mSubBox.endFill();
  136.       }
  137.       this.mSubBox._x = this.tfSubBox._x;
  138.       this.mSubBox._y = this.tfSubBox._y;
  139.       this.mSubBox._width = this.tfSubBox._width;
  140.       this.mSubBox._height = this.tfSubBox._height;
  141.    }
  142. };
  143. _global.synchroneCLASS.prototype.load = function(target, videoFile, subtitleFile, textX, textY)
  144. {
  145.    if(!this.target instanceof MovieClip)
  146.    {
  147.       return undefined;
  148.    }
  149.    this.target = target;
  150.    this.targetInitBytes = this.target.getBytesTotal();
  151.    if(subtitleFile != null)
  152.    {
  153.       if(parseFloat(textX) != textX.toString() || textX == null)
  154.       {
  155.          delete this.textX;
  156.       }
  157.       else
  158.       {
  159.          this.textX = textX;
  160.       }
  161.       if(parseFloat(textY) != textY.toString() || textY == null)
  162.       {
  163.          delete this.textY;
  164.       }
  165.       else
  166.       {
  167.          this.textY = textY;
  168.       }
  169.       this.subObj = new Object();
  170.       this.lastSubText = null;
  171.       this.useSubtitle = true;
  172.       this.subParser = new _global.subParserCLASS();
  173.       this.subParser.load(subtitleFile,this.subObj);
  174.    }
  175.    else
  176.    {
  177.       this.useSubtitle = false;
  178.    }
  179.    this.videoFile = videoFile;
  180.    this.target.loadMovie(this.videoFile);
  181.    this.videoPreloaderInterval = setInterval(this,"videoPreloader",1000 / (_global.FPS + 1));
  182.    this.videoPreloader();
  183. };
  184. _global.synchroneCLASS.prototype.setOnData = function(target, method)
  185. {
  186.    this.onDataTarget = target;
  187.    this.onDataMethod = method;
  188.    this.onDataArguments = arguments.slice(2);
  189. };
  190. _global.synchroneCLASS.prototype.getOnData = function(target, name)
  191. {
  192.    return this.onDataTarget[this.onDataMethod];
  193. };
  194. _global.synchroneCLASS.prototype.setBox = function(state)
  195. {
  196.    this.box = !state ? false : true;
  197. };
  198. _global.synchroneCLASS.prototype.getBox = function()
  199. {
  200.    return this.box;
  201. };
  202. _global.synchroneCLASS.prototype.setShade = function(state)
  203. {
  204.    this.shade = !state ? false : true;
  205. };
  206. _global.synchroneCLASS.prototype.getShade = function()
  207. {
  208.    return this.shade;
  209. };
  210. _global.synchroneCLASS.prototype.unload = function()
  211. {
  212.    clearInterval(this.synchronizeInterval);
  213.    this.target.unloadMovie();
  214.    this.subParser.unload();
  215. };
  216.